<div class="panel-body">
	<div class="table-responsive">
		<div class="dataTables_wrapper form-inline" id="dataTables-example_wrapper" role="grid">
			<div class="row" style="padding-bottom: 15px">
				<div class="col-sm-9">
					<div class="dataTables_length" id="dataTables-example_length">
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="area" onchange="changearea()">
							<option value="">区/县</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="work" onchange="changeTwon()">
							<option value="">分局</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="wangge">
							<option value="">网格</option>
						</select>
						<a class="btn btn-serch" onclick="Search()">查询</a>
						<a class="btn btn-serch" style="background: #3cbeb2;cursor:pointer !important;" data-options="iconCls:'icon-redo'" id="import">导入</a>
						<!--<a class="btn btn-serch" style="background-color: #5a82f1;" onclick="ToExcel()">导出</a>-->
						<a class="btn btn-serch" style="background-color: #737eac;" onclick="ToTemplate()">模板下载</a>
					</div>
				</div>
				<div class="col-sm-3">
					<div class="dataTables_filter" id="dataTables-example_filter" style="float: right">
						<a class="btn btn-serch" onclick="AddSysUser()">新增 </a>
					</div>
				</div>
			</div>
			<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" aria-describedby="dataTables-example_info">
				<thead>
					<tr role="row">
						<th tabindex="0" class="sorting_asc" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">序号
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">登录名
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">姓名
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 15%;" rowspan="1" colspan="1">邮箱
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">电话
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 15%;" rowspan="1" colspan="1">部门
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 7%;" rowspan="1" colspan="1">区县
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 7%;" rowspan="1" colspan="1">分局
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 7%;" rowspan="1" colspan="1">网格
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 4%;" rowspan="1" colspan="1">状态
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">操作
						</th>
					</tr>
				</thead>
				<tbody id="SysUserlist">

				</tbody>
			</table>
			<div class="row">
				<div id="page" style="float: right"></div>
			</div>
		</div>
	</div>

</div>
<script>
	$(function() {
		$("#import").upload({
			action: GLOBAL.URL + "/dataload/upload?type=user",
			name: 'file',
			autoSubmit:true,
			onComplete: function(data, self, element) {
				datas=JSON.parse(data);
				if(datas.code == 0) {
					AlertInfo("数据导入成功！");
				} else {
					AlertInfo(datas.code);
				}
			}
		});

		//加载数据
		getdata(1);
		GetArea();
	});
	////请求列表
	function getdata(page) {
		var json = {
			"url": GLOBAL.URL + "/sys/user/list",
			"type": 'post',
			"data": {
				"page": page,
				"limit": 15,
				"countryName":$("#area").val(),
				"branchOffice":$("#work").val(),
				"guidName":$("#wangge").val()
			},
			successfn: function(data) {
				UpdateSysUserList(data.page.list);
				setPage(data.page.totalPage);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);

	}
	////加载列表数据
	function UpdateSysUserList(data) {
		var listStr = "";
		if(data != null) {
			for(var i = 0; i < data.length; i++) {
				data[i].username = data[i].username == null ? "" : data[i].username;
				data[i].realName = data[i].realName == null ? "" : data[i].realName;
				data[i].email = data[i].email == null ? "" : data[i].email;
				data[i].mobile = data[i].mobile == null ? "" : data[i].mobile;
				data[i].deptName = data[i].deptName == null ? "" : data[i].deptName;
				data[i].countryName = data[i].countryName == null ? "" : data[i].countryName;
				data[i].branchOffice = data[i].branchOffice == null ? "" : data[i].branchOffice;
				data[i].guidName = data[i].guidName == null ? "" : data[i].guidName;
				data[i].status = data[i].status == null ? "" : data[i].status;
				if(data[i].status!="" && data[i].status==1){
					data[i].status="启用";
				}else if(data[i].status!="" && data[i].status==2){
					data[i].status="停用";
				}
				if((i + 1) % 2 > 0) {
					listStr += '<tr  class="gradeA odd">';
					listStr += '<td style="text-align: center;">' + (i + 1) + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].username + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].realName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].email + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].mobile + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].deptName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].countryName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].branchOffice + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].guidName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].status + '</td>';
					listStr += '<td  style="text-align:center;"><a onclick="EditSysUser(' + data[i].userId + ')">编辑</a> <a onclick="DelSysUser(' + data[i].userId + ')">删除</a></td>';
					listStr += '</tr>';
				} else {
					listStr += '<tr class="gradeA even">';
					listStr += '<td style="text-align: center;">' + (i + 1) + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].username + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].realName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].email + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].mobile + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].deptName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].countryName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].branchOffice + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].guidName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].status + '</td>';
					listStr += '<td  style="text-align:center;"><a onclick="EditSysUser(' + data[i].userId + ')">编辑</a> <a onclick="DelSysUser(' + data[i].userId + ')">删除</a></td>';
					listStr += '</tr>';
				}
			}
		}
		$("#SysUserlist").html(listStr);
	}
	//新增系统人员
	function AddSysUser() {
		GLOBAL.LOADURl = "Page/system/systeamuser/index.html";
		SaveDialog("#AddSysUser", "Page/system/systeamuser/addsysuser.html", "/sys/user/save", "新增系统人员");
	}
	//编辑系统人员
	function EditSysUser(ID) {
		GLOBAL.LOADURl = "Page/system/systeamuser/index.html";
		SaveDialog("#EditSysUser", "Page/system/systeamuser/editsysuser.html", "/sys/user/update", "编辑系统人员", function() {
			$.ajax({
				type: 'get', //请求的类型
				url: GLOBAL.URL + "/sys/user/info/" + ID, //请求的地址
				dataType: "json", //返会值的类型
				async: false,
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				success: function(datas, textStatus) { //请求成功执行的代码
					if(datas.code == 0) {
						if(datas.info.countryName!=null && datas.info.countryName!=""){
						    GetWork(datas.info.countryName);
						}
						if(datas.info.countryName!=null && datas.info.countryName!="" && datas.info.branchOffice !=null && datas.info.branchOffice!=""){
						Getwangge(datas.info.countryName, datas.info.branchOffice);
						}
					}
				}
			});
			loadForm("#EditSysUser", "/sys/user/info/" + ID);
			$("#userId").val(ID);
		});
	}
	//删除系统人员
	var deleteSysUser = function(ID, dblChoseAlert) {
		$.ajax({
			type: 'get', //请求的类型
			url: GLOBAL.URL + "/sys/user/delete?ids=" + ID, //请求的地址
			dataType: "json", //返会值的类型
			async: false,
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			success: function(datas, textStatus) { //请求成功执行的代码
				if(datas.code == 0) {
					var onlyChoseAlert = simpleAlert({
						"content": "删除成功！",
						"buttons": {
							"确定": function() {
								getdata(1);
								dblChoseAlert.close();
								onlyChoseAlert.close();
							}
						}
					});
				} else if(datas.code == "403") {
					AlertInfo("操作失败！" + datas.msg);
					window.location.href = "login.html";
				} else {
					AlertInfo("请求失败！" + datas.msg);
				}
			},
			error: function() {
				json.errorfn();
			}

		});
	}

	function DelSysUser(ID) {
		AlertDel(deleteSysUser, ID);
	}
	
	//查询
	function Search() {
		getdata(1);
	}
	//获取区县
	function GetArea() {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"queryType": 0,
				"scope": 2
			},
			successfn: function(data) {
				SetArea(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetArea(data) {
		var str = '<option value="">区/县</option>';
		for(var i = 0; i < data.length; i++) {
			str += '<option value="' + data[i].countryName + '">' + data[i].countryName + '</option>';
		}
		$("#area").html(str);
	}
	//区县点击
	function changearea() {
		if($("#area").val() == "") {
			$("#work").html('<option value="">分局</option>');
			$("#wangge").html('<option value="">网格</option>');
		} else {
			GetWork($("#area").val());
		}
	}
	//获取分局
	function GetWork(areastr) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"area": areastr,
				"queryType": 1,
				"scope": 2
			},
			successfn: function(data) {
				SetWork(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWork(data) {
		var str = '<option value="">分局</option>';
		for(var i = 0; i < data.length; i++) {
			if(data[i] != null) {
				str += '<option value="' + data[i].branchOffice + '">' + data[i].branchOffice + '</option>';
			}
		}
		$("#work").html(str);
	}
	//分局点击
	function changeTwon() {
		if($("#area").val() == "" || $("#work").val() == "") {
			$("#wangge").html('<option value="">网格</option>');
		} else {
			Getwangge($("#area").val(), $("#work").val());
		}
	}
	//获取网格
	function Getwangge(areastr, workstr) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"area": areastr,
				"town": workstr,
				"queryType": 2,
				"scope": 0

			},
			successfn: function(data) {
				SetWangge(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWangge(data) {
		var str = '<option value="">网格</option>';
		for(var i = 0; i < data.length; i++) {
			str += '<option value="' + data[i].gridName + '">' + data[i].gridName + '</option>';
		}
		$("#wangge").html(str);
	}
	
	
	/*function ToExcel() {
        var countryName= $("#area").val();
		var branchOffice= $("#work").val();
		var guidName= $("#wangge").val();
		window.open("http://111.9.116.31:8098/chinamobile/shopinfo/download?countryName="+countryName+"&branchOffice="+branchOffice+"&gridName="+guidName);
	}*/
	
			//模板下载
	function ToTemplate(){
		window.open(GLOBAL.URL +"/template/user_template.xlsx");
	}
</script>